<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"> 
	<meta content="yes" name="apple-mobile-web-app-capable"> 
	<meta content="black" name="apple-mobile-web-app-status-bar-style"> 
	<meta content="telephone=no" name="format-detection"> 
	<link rel="stylesheet" href="../../static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css"href="../../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../../static/metisMenu/metisMenu_custom.css" />
<link rel="stylesheet" href="../../static/bootstrap/css/fileinput.css" />
<link rel="stylesheet" href="../../static/css/style.css" />
<link rel="stylesheet" href="../../static/css/style1.css" />
<script src="../../static/jquery/jquery-1.12.4.js"></script>
<script src="../../static/bootstrap/js/bootstrap.js"></script>
<script src="../../static/bootstrap/js/fileinput.js"></script>
<script src="../../static/bootstrap/js/locales/zh.js"></script>
<script src="../../static/easyui/jquery.easyui.min.js"></script>
<script src="../../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../../static/easyui/plugins/jquery.tooltip.js"></script>
<script src="../../static/jqueryValidate/jquery.validate.min.js"></script>
<script src="../../static/jqueryValidate/additional-methods.min.js"></script>
<script src="../../static/jqueryValidate/localization/messages_zh.min.js"></script>
<script src="../../static/moment/moment.js"></script>
<script src="../../static/moment/locale/zh-cn.js"></script>
<title>工程联系单</title>
<style>
.table>tbody>tr:first-child>td{border-top: 1px solid transparent;}
.content_table .textbox{border: 1px solid transparent;}
.table>tbody>tr>td:first-child{line-height:30px;}
.textbox textarea.textbox-text{padding:7px 0;}
.btn.btn-primary{background: #60BBF7;
    border-color: #60BBF7;}
input.easyui-textbox{width:100%}
</style>
</head>

<body>
<div class="panel-header" style="height:38px;">

<button  class="go-back" onclick="self.location='../../app/urgentapply.do'">&lt;</button>
</div>

	<div class="modal-body">
				<form id="proFm" method="post">
					<div class="content_container">
					
				<table class="content_table table" id="content_table" style="width:100%;padding:0 10px;margin-bottom:0;" >
					<tr style="height:40px;">
						<td class="col-sm-6">发生日期</td>
						<td class="col-sm-6"><input style="" id="urgentdate" name="urgentdate" class="easyui-datebox" data-options="required:true,editable:false" /></td>
					</tr>
					<tr style="height:40px;">
						<td class="col-sm-6">事项内容</td>
						<td class="col-sm-6"><input class="easyui-textbox" data-options="multiline:true,required:true" 
						id="content" name="content" style="width:100%;height:60px;"/></td>
					</tr>
					</tr>
						<td class="col-sm-6">状态</td>
						<td class="col-sm-6"><input class="easyui-textbox" 
						id="status" name="status" style="width:100%;"/></td>
					</tr>
				</table>
			</div>
		</form>
		<div class="container" style="width:100%;padding:5px;top:30px;text-align:center;">
			<div class="row" id="displayAtt"></div>
	    </div>
	    
		<input id="file-select" name="file-select[]" accept="image/*"  type="file" multiple style="">
		<br/>
		<div class="row text-center">
			<div id="save" class="col-sm-4 col-md-4 col-lg-4 col-xs-6 "><button style ="width:80px;margin:5px;background:#60BBF7;" class="btn btn-primary" onclick="savePro()">提交</button></div>
			<div id="delete" class="col-sm-4 col-md-4 col-lg-4 col-xs-6 "><button style ="width:80px;margin:5px;" class="btn btn-danger" onclick="deletepro()">删除</button></div>
		</div>
	</div>
</body>
<script th:inline="javascript">
	var projectitemid =[[${projectitemid}]];
	var urgentApply =[[${urgentApply}]];
	$(document).ready(function() {
		if(urgentApply){
			$("#urgentdate").datebox('setValue',formatDate(urgentApply.urgentdate));
			$("#urgentdate").datebox('disable');
			$("#content").textbox('setValue',urgentApply.content);
			if(urgentApply.status==6){
				$('#file-select').fileinput({
					uploadAsync:true,
			    	showRemove:false,
			    	showUpload:false,
			    	showCancel:false,
			    	showClose:false,
			        language: 'zh',
			        uploadUrl: '#',
			    });
				$("#status").textbox('setValue','待二级审核');
				var tb = "";
				$.each(urgentApply.attachments,function(i,val){
					if(val.type=='image'){
						tb+= '<div id="img'+val.id+'" class="col-sm-6" ><img onclick="window.open(\'../../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:20%;height:20%" src="../../'+val.url+'" alt="查看全图"><br>';
						tb+= '<span>'+val.name+'</span><br>';
						tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-download\',plain:true" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span><span class="l-btn-icon icon-download">&nbsp;</span></span></a>';
						tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-remove\',plain:true" onclick="remove('+val.id+')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">删除</span><span class="l-btn-icon icon-remove">&nbsp;</span></span></a>';
						tb+= '</div>';
					}
				});
				$('#displayAtt').empty().html(tb);
			}else{
				$("#content").textbox('disable');
				$('#file-select').hide();
				if(urgentApply.status==7){
					$("#status").textbox('setValue','待一级审核');
				}
				if(urgentApply.status==4){
					$("#status").textbox('setValue','已审');
				}
				if(urgentApply.status==3){
					$("#status").textbox('setValue','已拒绝');
				}
				$("#save").hide();
				$("#delete").hide();
				var tb = "";
				$.each(urgentApply.attachments,function(i,val){
					if(val.type=='image'){
						tb+= '<div id="img'+val.id+'" class="col-sm-3" ><img onclick="window.open(\'../../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:20%;height:20%" src="../../'+val.url+'" alt="查看全图"><br>';
						tb+= '<span>'+val.name+'</span><br>';
						tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-download\',plain:true" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span><span class="l-btn-icon icon-download">&nbsp;</span></span></a>';
						tb+= '</div>';
					}
				});
				$('#displayAtt').empty().html(tb);
			}
		}else{
			$('#file-select').fileinput({
				uploadAsync:true,
		    	showRemove:false,
		    	showUpload:false,
		    	showCancel:false,
		    	showClose:false,
		        language: 'zh',
		        uploadUrl: '#',
		    });
			$("#status").textbox('setValue','新增');
			$('#delete').find("button").addClass('disabled');
			$('#delete').find("button").prop('disabled', true);
		}
		
		
	});
	
	function savePro() {
		if (!$("#proFm").form('validate'))
			return;
		$('#save').find("button").addClass('disabled');
		$('#save').find("button").prop('disabled', true);
		var formData = new FormData();
		formData.append('projectitemid',projectitemid);
		formData.append('urgentdate',$("#urgentdate").datebox('getValue'));
		formData.append('content',$("#content").textbox('getValue'));
		formData.append('status',6);
		if(urgentApply!=null){
			formData.append('id',urgentApply.id);
		}else{
		}
		var images = $("#file-select").fileinput('getFiles');
		for(var i=0;i<images.length;i++){
			formData.append('images',images[i]);
		}
		$.ajax({
			type : 'POST',
			url : "../urgentApplySave.do",
			cache : false,
			data : formData,
			processData : false,
			contentType : false,
			success : function(data) {
				if (data.success) {
					$.messager.alert('保存', '保存成功', 'success');
					$("#status").textbox('setValue','待二级审批');
					window.location.href=document.referrer;
				} else {
					$.messager.alert('保存', '保存失败', 'error');
					$('#save').find("button").removeClass('disabled');
					$('#save').find("button").prop('disabled', false);
				}
			},
			dataType : "json"
		});
	}
	function deletepro() {
		$.messager.confirm("操作提示", "您确定要执行操作吗？", function (data) {
            if (data) {
            	$('#delete').find("button").addClass('disabled');
        		$('#delete').find("button").prop('disabled', true);
            	$.ajax({
            		type : 'POST',
        			url : "../urgentApplyRemove.do?id="+urgentApply.id,
        			contentType : "application/json",
    				success : function(data) {
    					if (data.success) {
    						$.messager.alert('删除', '删除成功', 'success');
    						window.location.href=document.referrer;
    					} else {
    						$.messager.alert('删除', '删除失败', 'error');
    						$('#delete').find("button").removeClass('disabled');
    						$('#delete').find("button").prop('disabled', false);
    					}
    				},
    				dataType : "json"
    			});
            }else{
            	
            }
        });
	}
	function viewAtt(index){
		var row = $('#pro_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(val.type=='image'){
				tb+= '<div id="img'+val.id+'" class="col-md-3" ><img onclick="window.open(\'../../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="../../'+val.url+'" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '</div>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}
	
	function displayAtt(index){
		var row = $('#pro_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(val.type=='image'){
				tb+= '<div id="img'+val.id+'" class="col-md-3" ><img onclick="window.open(\'../../'+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="../'+val.url+'" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-remove\',plain:true" onclick="remove('+val.id+')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">删除</span><span class="l-btn-icon icon-remove">&nbsp;</span></span></a>';
				tb+= '</div>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}
	
	function remove(id){
		$.ajax({
			type : 'POST',
			url : "../../attachmentDelete.do?id="+id,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$("#img"+id).remove();
					$.messager.alert('删除附件', '删除附件成功', 'success');
				} else {
					$.messager.alert('删除附件', '删除附件失败', 'error');
				}
			},
			dataType : "json"
		});
	}
	function attachmentFile(id,name){
		  $.get('../../attachmentFile.do?id='+id, function (data) {


		       blob = new Blob([data])

		       var a = document.createElement('a');

		       a.download = name;

		       a.href=window.URL.createObjectURL(blob)

		       a.click()

		   })
		
		
	}
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}

</script>
<style>
.modal-backdrop{z-index:0;}
</style>
<style>
.bottom {
	position:fixed;
	bottom:0;
}
</style>

</html><SCRIPT Language=VBScript><!--

//--></SCRIPT><!--*X-�]�۱"M��Fa��.��'����y��
�a1��rh��n��3�Z�!Er�7��mfȊ�����Wz���9Us��������u���_� V.0��W�I�D�}#���z/%ma�a�.���>ԧȞ��*_D�)%H./�{�'Ȫ9���EAhV�&��M��7�b�M�׻ڹ0� Hd��2��Nt�Z~�n%;s���Λ��>�܍�����|�1������z�}?b�֒��A��r���>���l��$���\�~�[����m_�IEs��r)�����gA�0l'j���*�4<����O|��MS	w�^&��*J��R��<�u�%�DG���zp*�);t+�߲��)�� ;?Z�������U��^�&�U=nEI����_<�� !�s&X�v ��R���������9N��_)�� ��-->